package forms;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap; // new import
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

import javax.swing.table.DefaultTableModel;                                      
import models.ProductModel;

/**
 *
 * @author lunnat
 */
public class Products extends javax.swing.JFrame {

    ProductModel db;
    DefaultTableModel model;
    HashMap<String, String> Hm; // create obj Hm as array[] type    || Category
    HashMap<String, String> bm; //                                 || Brand
    int t=0;
    public Products() {
        initComponents();
        db = new ProductModel();
        model = (DefaultTableModel) tblProducts.getModel();
        
        // lord data from database to combobox
        //this.LordCombo();
        //  this.reloadData();
        
        // disable property when FormLord 
        this.DisOption();
      

    }
    private void OPenOption(){
        txtName.setEnabled(true);
        txtPrice.setEnabled(true);
        txtPrice.setEnabled(true);
        txtCost.setEnabled(true);
        txtQty_in.setEnabled(true);
        txtQty_out.setEnabled(true);
        txtImage.setEnabled(true);
        txtDescrytion.setEnabled(true);
    }
    // disable property 
    private void DisOption(){
      this.btnAdd.setEnabled(false);
      this.btnDelete.setEnabled(false);
      this.btnUpdate.setEnabled(false);
      
      this.txtSearch.setEnabled(false);
      this.txtID.setEnabled(false);
      
      this.lblID.setEnabled(false);
      this.txtName.setEnabled(false);
      this.txtPrice.setEnabled(false);
      this.txtPrice.setEnabled(false);
      this.txtCost.setEnabled(false);
      this.txtQty_in.setEnabled(false);
      this.txtQty_out.setEnabled(false);
      this.txtImage.setEnabled(false);
      this.txtDescrytion.setEnabled(false);
      
      this.jcbBrand.setEnabled(false);
      this.jcbCategory.setEnabled(false);
        
      
    }
    // Lord data from database to comboBox
    private void LordCombo() {
      
        // category
        Hm = new HashMap<String, String>();
        ResultSet rs = db.select("SELECT * FROM categories");
        //  ResultSet rs = db.select("SELECT cat_id,cat_name FROM categories");
        try {
            while (rs.next()) {
                jcbCategory.addItem(rs.getString("cat_name"));
                Hm.put(rs.getString("cat_name"), rs.getString("cat_id"));
            }
        } catch (SQLException ex) {
            Logger.getLogger(MyCombobox.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        // finish
        //----------------------------------------------------------------------
        
        // brand
        bm = new HashMap<String,String>();
        ResultSet rsbrand = db.select("select * from brands where bra_Type =" + 1);
        //ResultSet rsbrand = db.select("select bra_id, bra_name from brands where bra_Type =" + 1);
        try{
            while(rsbrand.next()){
                 jcbBrand.addItem(rsbrand.getString("bra_name"));
                bm.put(rsbrand.getString("bra_name"), rsbrand.getString("bra_id"));
            }
        }catch (SQLException ex) {
             Logger.getLogger(MyCombobox.class.getName()).log(Level.SEVERE, null, ex);
        }
            
    }

    // load data from database to table 
    public void reloadData() {
        try {
            model.setRowCount(0);
            String sql = "SELECT * FROM products";
            ResultSet rs = db.select(sql);

            while (rs.next()) {
                int id = rs.getInt("pro_id");
                String name = rs.getString("pro_name");
                int price = rs.getInt("pro_price");
                int cost = rs.getInt("pro_cost");
                int qty_in = rs.getInt("pro_qty_in");
                int qty_out = rs.getInt("pro_qty_out");
                String image = rs.getString("pro_image");
                String des = rs.getString("pro_des");
                int categoryid = rs.getInt("pro_categoryid");
                String brand = rs.getString("pro_brandid");
                // Add row to table interface
                Object[] rowData = new Object[]{id, name, price, cost, qty_in, qty_out, image, des, categoryid, brand};

                model.addRow(rowData);
            }
            db.close();

        } catch (SQLException ex) {
            Logger.getLogger(Groups.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    // Clear Form
    public void ClearForm() {

        this.txtID.setText("");
        this.txtName.setText("");
        this.txtPrice.setText("");
        this.txtCost.setText("");
        this.txtQty_in.setText("");
        this.txtQty_out.setText("");
        this.txtImage.setText("");
        this.txtDescrytion.setText("");
       

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblProducts = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        txtQty_in = new javax.swing.JTextField();
        txtName = new javax.swing.JTextField();
        txtPro_des = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtImage = new javax.swing.JTextField();
        txtID = new javax.swing.JTextField();
        txtPrice = new javax.swing.JTextField();
        txtQty_out = new javax.swing.JTextField();
        txtCost = new javax.swing.JTextField();
        lblID = new javax.swing.JLabel();
        txt = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        txtDescrytion = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        btnUpdate = new javax.swing.JButton();
        btnDelete = new javax.swing.JButton();
        btnAdd = new javax.swing.JButton();
        lblName = new javax.swing.JLabel();
        lblPrice = new javax.swing.JLabel();
        lblCost = new javax.swing.JLabel();
        lblQty_in = new javax.swing.JLabel();
        lblDes = new javax.swing.JLabel();
        lblQty_out = new javax.swing.JLabel();
        lblCate = new javax.swing.JLabel();
        lblBrand = new javax.swing.JLabel();
        lblImage = new javax.swing.JLabel();
        jcbCategory = new javax.swing.JComboBox();
        jcbBrand = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        txtSearch = new javax.swing.JTextField();
        btnSearch = new javax.swing.JButton();
        cbProducts = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel2.setName("Products"); // NOI18N

        tblProducts.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Pro_ID", "Pro_Name", "Pro_price", "Pro_Cost", "Pro_qty_In", "Pro_qty_Out", "Pro_Image", "Pro_descrtion", "Pro_categoryID", "pro_brandID"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblProducts.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblProductsMouseClicked(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                tblProductsMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tblProductsMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                tblProductsMouseReleased(evt);
            }
        });
        jScrollPane1.setViewportView(tblProducts);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("AdNew_Product"));
        jPanel1.setEnabled(false);

        txtQty_in.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseExited(java.awt.event.MouseEvent evt) {
                txtQty_inMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                txtQty_inMousePressed(evt);
            }
        });

        txtName.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseExited(java.awt.event.MouseEvent evt) {
                txtNameMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                txtNameMousePressed(evt);
            }
        });
        txtName.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNameKeyPressed(evt);
            }
        });

        txtPro_des.setText("ProductImage :");

        jLabel6.setText("ProdcutQty_in :");

        jLabel5.setText("ProdcutCost :");

        txtImage.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseExited(java.awt.event.MouseEvent evt) {
                txtImageMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                txtImageMousePressed(evt);
            }
        });

        txtPrice.setToolTipText("");
        txtPrice.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseExited(java.awt.event.MouseEvent evt) {
                txtPriceMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                txtPriceMousePressed(evt);
            }
        });

        txtQty_out.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseExited(java.awt.event.MouseEvent evt) {
                txtQty_outMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                txtQty_outMousePressed(evt);
            }
        });

        txtCost.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseExited(java.awt.event.MouseEvent evt) {
                txtCostMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                txtCostMousePressed(evt);
            }
        });

        lblID.setText("ProductID :");

        txt.setText("ProductBrand :");

        jLabel11.setText("ProductCategory :");

        txtDescrytion.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseExited(java.awt.event.MouseEvent evt) {
                txtDescrytionMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                txtDescrytionMousePressed(evt);
            }
        });

        jLabel3.setText("ProdcutName :");

        jLabel4.setText("ProdcutPrice :");

        jLabel9.setText("ProductQty_out :");

        jLabel10.setText("ProductDescrition :");

        btnUpdate.setText("Update");
        btnUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdateActionPerformed(evt);
            }
        });

        btnDelete.setText("Delete");
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });

        btnAdd.setText("Submit");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        lblName.setForeground(new java.awt.Color(255, 51, 51));
        lblName.setText("Charactor Only");
        lblName.setEnabled(false);

        lblPrice.setForeground(new java.awt.Color(255, 51, 51));
        lblPrice.setText("Number Only");
        lblPrice.setEnabled(false);

        lblCost.setForeground(new java.awt.Color(255, 51, 51));
        lblCost.setText("Number Only");
        lblCost.setEnabled(false);

        lblQty_in.setForeground(new java.awt.Color(255, 51, 51));
        lblQty_in.setText("Number Only");
        lblQty_in.setEnabled(false);

        lblDes.setForeground(new java.awt.Color(255, 51, 51));
        lblDes.setText("Charactor Only");
        lblDes.setEnabled(false);

        lblQty_out.setForeground(new java.awt.Color(255, 51, 51));
        lblQty_out.setText("Number Only");
        lblQty_out.setEnabled(false);

        lblCate.setForeground(new java.awt.Color(255, 51, 51));
        lblCate.setText("Number Only");
        lblCate.setEnabled(false);

        lblBrand.setForeground(new java.awt.Color(255, 51, 51));
        lblBrand.setText("Number Only");
        lblBrand.setEnabled(false);

        lblImage.setForeground(new java.awt.Color(255, 51, 51));
        lblImage.setText("Charactor Only");
        lblImage.setEnabled(false);

        jcbCategory.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jcbCategoryMouseClicked(evt);
            }
        });
        jcbCategory.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcbCategoryItemStateChanged(evt);
            }
        });

        jcbBrand.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbBrandActionPerformed(evt);
            }
        });

        jButton1.setText("Add_new_product");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel6))
                                .addGap(30, 30, 30)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(txtQty_in, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(lblQty_in))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(txtCost, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(lblCost))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(txtPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(lblPrice))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(lblName))
                                    .addComponent(txtID, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(lblID))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txt, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtPro_des, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(28, 28, 28))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(480, 480, 480)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtDescrytion, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                            .addComponent(txtQty_out, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                            .addComponent(txtImage, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                            .addComponent(jcbCategory, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jcbBrand, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblImage)
                            .addComponent(lblQty_out)
                            .addComponent(lblDes)
                            .addComponent(lblCate)
                            .addComponent(lblBrand))
                        .addContainerGap(142, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btnAdd)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnUpdate)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnDelete)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtQty_out, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblQty_out)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtImage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblImage)
                            .addComponent(txtPro_des))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtDescrytion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblDes)
                            .addComponent(jLabel10))
                        .addGap(21, 21, 21)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblCate)
                            .addComponent(jLabel11)
                            .addComponent(jcbCategory, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txt)
                            .addComponent(lblBrand)
                            .addComponent(jcbBrand, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblID)
                            .addComponent(txtID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblName))
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtPrice, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel4)
                                .addComponent(lblPrice)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(txtCost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblCost))
                        .addGap(9, 9, 9)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(txtQty_in, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblQty_in)))))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAdd)
                    .addComponent(btnUpdate)
                    .addComponent(btnDelete)
                    .addComponent(jButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel2.setBackground(new java.awt.Color(255, 51, 51));
        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel2.setText("Products");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Search"));

        txtSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtSearchActionPerformed(evt);
            }
        });

        btnSearch.setText("Search");
        btnSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchActionPerformed(evt);
            }
        });

        cbProducts.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All", "pro_id", "pro_name", "pro_categoryid", "pro_brandid" }));
        cbProducts.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cbProductsMouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                cbProductsMousePressed(evt);
            }
        });
        cbProducts.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                cbProductsMouseDragged(evt);
            }
        });
        cbProducts.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbProductsActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(cbProducts, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnSearch)
                .addContainerGap(30, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSearch)
                    .addComponent(cbProducts, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel2)
                        .addGap(153, 153, 153))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1019, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap(12, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdateActionPerformed
        removeAll();
        int id = Integer.parseInt(this.txtID.getText());
        String name = this.txtName.getText();
        int price = Integer.parseInt(this.txtPrice.getText());
        int cost = Integer.parseInt(this.txtCost.getText());
        int qty_in = Integer.parseInt(this.txtQty_in.getText());
        int qty_out = Integer.parseInt(this.txtQty_out.getText());
        String image = this.txtImage.getText();
        String des = this.txtDescrytion.getText();
       // int cate        = Integer.parseInt(this.jcbCategory.get());
        // int brand       = Integer.parseInt(this.txtBrandID.getText());
        
        
        String sql = "UPDATE products set pro_name='" + name + "', pro_price='" + price + "', pro_cost='" + cost + "', pro_qty_in='" + qty_in + "', pro_qty_out='" + qty_out + "', pro_image='" + image + "', pro_des='" + des + "' WHERE pro_id=" + id;
        //System.out.println(sql);
        this.db.update(sql);
        this.reloadData();
        this.ClearForm();

        // Disable button
        this.btnAdd.setEnabled(false);
        this.btnDelete.setEnabled(false);
        this.btnUpdate.setEnabled(false);

    }//GEN-LAST:event_btnUpdateActionPerformed

    private void txtSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtSearchActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtSearchActionPerformed

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed

        Object brand = jcbBrand.getSelectedItem();
        Object cate = jcbCategory.getSelectedItem();

      //  Object brandzz = Integer.parseInt(Hm.get(brand).toString());
      //  Object Catezz = Integer.parseInt(Hm.get(cate).toString());
        Object brandzz = Hm.get(brand);
        Object Catezz = Hm.get(cate);
        JOptionPane.showMessageDialog(null,""+brandzz );
        JOptionPane.showMessageDialog(null,""+Catezz);


        String name = this.txtName.getText();
        double price = Integer.parseInt(this.txtPrice.getText());
        double cost = Integer.parseInt(this.txtCost.getText());
        double qty_in = Integer.parseInt(this.txtQty_in.getText());
        double qty_out = Integer.parseInt(this.txtQty_out.getText());
        String image = this.txtImage.getText();
        String des = this.txtDescrytion.getText();

        // double cate     =  Integer.parseInt(this.txtCategoryID.getText()); // 
        //double brand    = Integer.parseInt(this.txtBrandID.getText());
        String sql = "INSERT INTO products (pro_name, pro_price, pro_cost, pro_qty_in, pro_qty_out, pro_image, pro_des, pro_categoryid, pro_brandid) "
                + "VALUES('" + name + "','" + price + "','" + cost + "','" + qty_in + "','" + qty_out + "','" + image + "','" + des + "','" + Catezz + "','" + brandzz + "')";

        //System.out.println(sql);
        this.db.insert(sql);

        // Close database connection
        this.db.close();
        // Reload data for jTable after click save button
        this.reloadData();
        // Clear Form
        this.ClearForm();
    }//GEN-LAST:event_btnAddActionPerformed

    private void tblProductsMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblProductsMousePressed
        jcbBrand.setEnabled(true);
        
        jcbCategory.removeAllItems();      // remove all item from jcbcategory
        jcbBrand.removeAllItems();        // remove all item from jcbcategory

        int selected_row = tblProducts.getSelectedRow();

        String id = (String) model.getValueAt(selected_row, 0).toString();
        String name = (String) model.getValueAt(selected_row, 1).toString();
        String price = (String) model.getValueAt(selected_row, 2).toString();
        String cost = (String) model.getValueAt(selected_row, 3).toString();
        String qty_in = (String) model.getValueAt(selected_row, 4).toString();
        String qty_out = (String) model.getValueAt(selected_row, 5).toString();
        String image = (String) model.getValueAt(selected_row, 6).toString();
        String des = (String) model.getValueAt(selected_row, 7).toString();
        String cate = (String) model.getValueAt(selected_row, 8).toString();
        String brand = (String) model.getValueAt(selected_row, 9).toString();

        // get value of IDcategory from database 
        try {
            String sql = "select cat_id,cat_name from categories where cat_id= '" + cate + "'";
            ResultSet rs = db.select(sql);
            if (rs.next()) {
                jcbCategory.addItem(rs.getString("cat_name"));
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }
        // finish

        // get value of IDbrand from database 
        try {
            String sql = "select bra_id,bra_name from brands where bra_id= '" + brand + "'";
            ResultSet rs = db.select(sql);
            if (rs.next()) {
                jcbBrand.addItem(rs.getString("bra_name"));
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }
        //finish

        // Fill data to form
        this.txtID.setText(id);
        this.txtName.setText(name);
        this.txtPrice.setText(price);
        this.txtCost.setText(cost);
        this.txtQty_in.setText(qty_in);
        this.txtQty_out.setText(qty_out);
        this.txtImage.setText(image);
        this.txtDescrytion.setText(des);
       // this.txtCategoryID.setText(cate);
        // this.txtBrandID.setText(brand);

        this.btnAdd.setEnabled(false);
        this.btnUpdate.setEnabled(true);
        this.btnDelete.setEnabled(true);

    }//GEN-LAST:event_tblProductsMousePressed


    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed

        if (JOptionPane.showConfirmDialog(null, "Are you sure you want to delete this item?") == JOptionPane.OK_OPTION) {

            int id = Integer.parseInt(this.txtID.getText());
            String sql = "DELETE FROM products WHERE pro_id=" + id;

            this.db.delete(sql);
            this.reloadData();
            this.ClearForm();

            // Disable button
            this.btnAdd.setEnabled(false);
            this.btnDelete.setEnabled(false);
            this.btnUpdate.setEnabled(false);
        }
    }//GEN-LAST:event_btnDeleteActionPerformed

    private void txtNameMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtNameMousePressed
        lblName.setEnabled(true);
    }//GEN-LAST:event_txtNameMousePressed

    private void txtNameMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtNameMouseExited
        lblName.setEnabled(false);
    }//GEN-LAST:event_txtNameMouseExited

    private void txtNameKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNameKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNameKeyPressed

    private void tblProductsMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblProductsMouseReleased

    }//GEN-LAST:event_tblProductsMouseReleased

    private void tblProductsMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblProductsMouseExited

    }//GEN-LAST:event_tblProductsMouseExited

    private void txtPriceMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtPriceMousePressed
        lblPrice.setEnabled(true);
    }//GEN-LAST:event_txtPriceMousePressed

    private void txtPriceMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtPriceMouseExited
        lblPrice.setEnabled(false);
    }//GEN-LAST:event_txtPriceMouseExited

    private void txtCostMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtCostMousePressed
        lblCost.setEnabled(true);
    }//GEN-LAST:event_txtCostMousePressed

    private void txtCostMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtCostMouseExited
        lblCost.setEnabled(false);
    }//GEN-LAST:event_txtCostMouseExited

    private void txtQty_inMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtQty_inMousePressed
        lblQty_in.setEnabled(true);
    }//GEN-LAST:event_txtQty_inMousePressed

    private void txtQty_inMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtQty_inMouseExited
        lblQty_in.setEnabled(false);
    }//GEN-LAST:event_txtQty_inMouseExited

    private void txtQty_outMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtQty_outMousePressed
        lblQty_out.setEnabled(true);
    }//GEN-LAST:event_txtQty_outMousePressed

    private void txtQty_outMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtQty_outMouseExited
        lblQty_out.setEnabled(false);
    }//GEN-LAST:event_txtQty_outMouseExited

    private void txtImageMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtImageMousePressed
        lblImage.setEnabled(true);
    }//GEN-LAST:event_txtImageMousePressed

    private void txtImageMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtImageMouseExited
        lblImage.setEnabled(false);
    }//GEN-LAST:event_txtImageMouseExited

    private void txtDescrytionMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtDescrytionMousePressed
        lblDes.setEnabled(true);
    }//GEN-LAST:event_txtDescrytionMousePressed

    private void txtDescrytionMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtDescrytionMouseExited
        lblDes.setEnabled(false);
    }//GEN-LAST:event_txtDescrytionMouseExited

    private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed

        try {
            model.setRowCount(0);
            String Combox = cbProducts.getSelectedItem().toString();
            Object obj = (Object) (this.txtSearch.getText());

            if (Combox == "All") {
                String sql = "SELECT * FROM products ";
                ResultSet rs = db.select(sql);
                if (!rs.next()){
                   //this.reloadData(); 
                   JOptionPane.showMessageDialog(null, "No Data In database"); 
                }
                else {
                    rs = db.select(sql);
                    while (rs.next()) {
                        int id = rs.getInt("pro_id");
                        String name = rs.getString("pro_name");
                        int price = rs.getInt("pro_price");
                        int cost = rs.getInt("pro_cost");
                        int qty_in = rs.getInt("pro_qty_in");
                        int qty_out = rs.getInt("pro_qty_out");
                        String image = rs.getString("pro_image");
                        String des = rs.getString("pro_des");
                        int categoryid = rs.getInt("pro_categoryid");
                        String brand = rs.getString("pro_brandid");

                        // Add row to table interface
                        Object[] rowData = new Object[]{id, name, price, cost, qty_in, qty_out, image, des, categoryid, brand};
                        model.addRow(rowData);
                    
                    }
                } 
                
            }
            else if(Combox == "pro_name") {
                // "SELECT * FROM brands where  bra_name LIKE '%"+ name +"%' "
                String sql = "select * from products where pro_name LIKE '%"+ obj +"%' ";
                ResultSet rs = db.select(sql);
                if (!rs.next()){
                    //this.reloadData();
                    JOptionPane.showMessageDialog(null, "Search not found !!"  );
                }
                else {
                    rs = db.select(sql);
                    while (rs.next()){
                        int id = rs.getInt("pro_id");
                        String name = rs.getString("pro_name");
                        int price = rs.getInt("pro_price");
                        int cost = rs.getInt("pro_cost");
                        int qty_in = rs.getInt("pro_qty_in");
                        int qty_out = rs.getInt("pro_qty_out");
                        String image = rs.getString("pro_image");
                        String des = rs.getString("pro_des");
                        int categoryid = rs.getInt("pro_categoryid");
                        String brand = rs.getString("pro_brandid");
                    
                        // Add row to table interface
                        Object[] rowData = new Object[]{id, name, price, cost, qty_in, qty_out, image, des, categoryid, brand};
                        model.addRow(rowData);   
                    }
                }
            
            }
            else {
                String sql = "SELECT * FROM products where " + Combox + "= '" + obj + "' ";
                ResultSet rs = db.select(sql);
                //JOptionPane.showMessageDialog(null, rs);
                if (!rs.next()){
                    //this.reloadData();
                    JOptionPane.showMessageDialog(null, "Search not found !!");
                }
                else{    
                    rs = db.select(sql);
                    while (rs.next()) {
                        int id = rs.getInt("pro_id");
                        String name = rs.getString("pro_name");
                        int price = rs.getInt("pro_price");
                        int cost = rs.getInt("pro_cost");
                        int qty_in = rs.getInt("pro_qty_in");
                        int qty_out = rs.getInt("pro_qty_out");
                        String image = rs.getString("pro_image");
                        String des = rs.getString("pro_des");
                        int categoryid = rs.getInt("pro_categoryid");
                        String brand = rs.getString("pro_brandid");
                        // Add row to table interface
                        Object[] rowData = new Object[]{id, name, price, cost, qty_in, qty_out, image, des, categoryid, brand};
                        model.addRow(rowData);
                        // how to show NO_data if we select Wrong id of table 
                    }
                }
                

            }
            db.close();
        } catch (SQLException ex) {
            Logger.getLogger(Groups.class.getName()).log(Level.SEVERE, null, ex);
            //JOptionPane.showMessageDialog(null, "Search not found !!");
        }

        this.ClearForm();

    }//GEN-LAST:event_btnSearchActionPerformed

    private void cbProductsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbProductsMouseClicked

    }//GEN-LAST:event_cbProductsMouseClicked

    private void cbProductsMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbProductsMousePressed


    }//GEN-LAST:event_cbProductsMousePressed

    private void cbProductsMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbProductsMouseDragged

    }//GEN-LAST:event_cbProductsMouseDragged

    private void cbProductsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbProductsActionPerformed
        String Combox = cbProducts.getSelectedItem().toString();
       
        if (Combox == "All") {
            txtSearch.setText("");
            this.txtSearch.setEnabled(false);
        } else {
            this.txtSearch.setEnabled(true);
        }
    }//GEN-LAST:event_cbProductsActionPerformed

    private void tblProductsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblProductsMouseClicked
        
        jcbBrand.setEnabled(true);
        jcbCategory.setEnabled(true);
        btnUpdate.setEnabled(true);
        btnDelete.setEnabled(true);
        
        OPenOption();
        
        
        
    }//GEN-LAST:event_tblProductsMouseClicked

    private void jcbBrandActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbBrandActionPerformed
        
    }//GEN-LAST:event_jcbBrandActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.LordCombo();
        //jcbBrand.removeAll();
        //jcbCategory.removeAll();
        
        
        ClearForm();
        txtName.setEnabled(true);
        txtPrice.setEnabled(true);
        txtPrice.setEnabled(true);
        txtCost.setEnabled(true);
        txtQty_in.setEnabled(true);
        txtQty_out.setEnabled(true);
        txtImage.setEnabled(true);
        txtDescrytion.setEnabled(true);
        jcbBrand.setEnabled(true);
        jcbCategory.setEnabled(true);
        btnAdd.setEnabled(true);
        
        
        
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jcbCategoryMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jcbCategoryMouseClicked
       bm = new HashMap<String, String>();
        jcbBrand.removeAllItems();
        
        try {
            Object s = jcbCategory.getSelectedItem();
             t = Integer.parseInt(Hm.get(s).toString());
            ResultSet rs = db.select("SELECT * FROM brands WHERE bra_type='" + t + "'");
            //ResultSet rs= db.select("select bra_id ,bra_name from brands where bra_type="+ t) ;
            while (rs.next()) {
                jcbBrand.addItem(rs.getString("bra_name"));
                bm.put(rs.getString("bra_name"), rs.getString("bra_id"));
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }
        
      
    }//GEN-LAST:event_jcbCategoryMouseClicked

    private void jcbCategoryItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcbCategoryItemStateChanged
          bm = new HashMap<String, String>();
        jcbBrand.removeAllItems();
        
        try {
            
            Object s = jcbCategory.getSelectedItem();
             t = Integer.parseInt(Hm.get(s).toString());
            ResultSet rs = db.select("SELECT * FROM brands WHERE bra_type='" + t + "'");
            //ResultSet rs= db.select("select bra_id ,bra_name from brands where bra_type="+ t) ;
            while (rs.next()) {
                jcbBrand.addItem(rs.getString("bra_name"));
                bm.put(rs.getString("bra_name"), rs.getString("bra_id"));
            }
        } catch (Exception e) {
          //  JOptionPane.showMessageDialog(null, e);  // ERROR ON HERE :(
        }
        
    }//GEN-LAST:event_jcbCategoryItemStateChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Products.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Products.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Products.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Products.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Products().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnSearch;
    private javax.swing.JButton btnUpdate;
    private javax.swing.JComboBox cbProducts;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox jcbBrand;
    private javax.swing.JComboBox jcbCategory;
    private javax.swing.JLabel lblBrand;
    private javax.swing.JLabel lblCate;
    private javax.swing.JLabel lblCost;
    private javax.swing.JLabel lblDes;
    private javax.swing.JLabel lblID;
    private javax.swing.JLabel lblImage;
    private javax.swing.JLabel lblName;
    private javax.swing.JLabel lblPrice;
    private javax.swing.JLabel lblQty_in;
    private javax.swing.JLabel lblQty_out;
    private javax.swing.JTable tblProducts;
    private javax.swing.JLabel txt;
    private javax.swing.JTextField txtCost;
    private javax.swing.JTextField txtDescrytion;
    private javax.swing.JTextField txtID;
    private javax.swing.JTextField txtImage;
    private javax.swing.JTextField txtName;
    private javax.swing.JTextField txtPrice;
    private javax.swing.JLabel txtPro_des;
    private javax.swing.JTextField txtQty_in;
    private javax.swing.JTextField txtQty_out;
    private javax.swing.JTextField txtSearch;
    // End of variables declaration//GEN-END:variables
}
